<?php
namespace Admin\Controller;

use Util\AccessController;


class ShBookController extends AccessController {


    public function Index() {
        $LS = Service('M', 'sh_book');
        $join = 'left join ts_book on ts_sh_book.ISBN = ts_book.ISBN';
        $files='ts_book.*,ts_sh_book.ISBN as ISBN,
        ts_sh_book.CREATETIME as HSETIME,ts_sh_book.ID as SHID,
        ts_sh_book.INFO as SHINFO,
        ts_sh_book.OPENID as OPENID,
        ts_sh_book.BOOK_ID ';
        $order ='HSETIME desc';
        $groud = 'ts_sh_book.ISBN';
        $DATA = $LS->join($where=null,$join,$files,null,null,$groud);
        $this->DATA = $DATA;
        $this->display();
    }

    //移除黑名单
    public function delete() {
        if($_POST['book_id']){//加入黑名单
            $LS1 = Service('M','book');
            $where['ID'] =$_POST['book_id'];
            $save['IS_BLACK'] =1;
            $LS1->update($where,$save);
        }
        $LS = Service('M', 'sh_book');
        $where['ID'] = $_POST['ID'];
        $OK = $LS->Del($where);
        echo $OK;
    }

    //加入黑名单
    public function Add() {
        $LS = Service('M', 'book');
        $where['ID'] = $_POST['ID'];
        $save['IS_BLACK'] = 1;
        $OK = $LS->update($where, $save);
        echo $OK;
    }

    //到处当当url的xls
    public function export_DD_url(){
        $LS = Service('M', 'sh_book');
        $join = 'left join ts_book on ts_sh_book.ISBN = ts_book.ISBN';
        $files='ts_sh_book.ISBN,ts_book.ID';
        $groud = 'ts_sh_book.ISBN';
        $where['ts_book.ID'] = array('exp','is  null');
        $bdata = $LS->join($where,$join,$files,null,null,$groud);
        foreach($bdata as $k => $v){
            $bdata[$k]['ID'] ='http://search.dangdang.com?key='.$v['ISBN'];
        }
        export($bdata,array('ISBN','URL'));
    }


}